package cn.tedu.weibo.controller;

import cn.tedu.weibo.common.response.JsonResult;
import cn.tedu.weibo.common.response.StatusCode;
import cn.tedu.weibo.mapper.UserMapper;
import cn.tedu.weibo.pojo.dto.UserLoginDTO;
import cn.tedu.weibo.pojo.dto.UserRegDTO;
import cn.tedu.weibo.pojo.entity.User;
import cn.tedu.weibo.pojo.vo.UserVO;
import cn.tedu.weibo.service.IUserService;
import cn.tedu.weibo.service.impl.UserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

@RestController
@RequestMapping("/v1/users/")
public class UserController {

    @Autowired
    IUserService userService;

    @PostMapping("reg")
    public JsonResult reg(@RequestBody UserRegDTO userRegDTO){
        userService.reg(userRegDTO);
        return JsonResult.ok();
    }
    @PostMapping("login")
    public JsonResult login(@RequestBody UserLoginDTO loginDTO){
        //把登录成功的当事人响应给客户端
        return JsonResult.ok(userService.login(loginDTO));
    }

    @GetMapping("logout")
    public JsonResult logout(){
        userService.logout();

        return JsonResult.ok();
    }

}
